<template>
	<view class="container">
		<!-- 店铺页面组件 -->
		<Page :items="items" />
	</view>
</template>

<script>
import Page from '@/components/page'
import data from './data'
import { scene_decode } from '@/utils/util.js'
const App = getApp()

export default {
	components: {
		Page
	},
	data() {
		return {
			// 页面参数
			options: {},
			// 页面属性
			page: {},
			// 页面元素
			items: []
		}
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad(options) {
		let scene = decodeURIComponent(options?.scene)
		let userInfo = this.$store.state.user.userInfo || {}
		let scene_obj = scene_decode(scene)
		if (scene_obj?.pId && scene_obj?.uid && scene_obj?.gId && scene_obj?.uid != userInfo.userId) {
			let obj = {
				id: scene_obj?.pId,
				uid: scene_obj?.uid,
				gId: scene_obj.gId
			}
			this.$navTo('pagesA/yanxue/yanxue_detail', obj)
		}
		// 当前页面参数
		this.options = options
		// 加载页面数据
		this.getPageData()
	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow() {},

	methods: {
		/**
		 * 加载页面数据
		 * @param {Object} callback
		 */
		getPageData(callback) {
			const app = this

			const { pageData } = data
			app.page = pageData.page
			app.items = pageData.items
			// 设置顶部导航栏栏
			app.setPageBar()
		},

		/**
		 * 设置顶部导航栏
		 */
		setPageBar() {
			const { page } = this
			// 设置页面标题
			uni.setNavigationBarTitle({
				title: page.params.title
			})
			// 设置navbar标题、颜色
			uni.setNavigationBarColor({
				frontColor: page.style.titleTextColor === 'white' ? '#ffffff' : '#000000',
				backgroundColor: page.style.titleBackgroundColor
			})
		}
	},

	/**
	 * 下拉刷新
	 */
	onPullDownRefresh() {
		// 获取首页数据
		this.getPageData(() => {
			uni.stopPullDownRefresh()
		})
	},

	/**
	 * 分享当前页面
	 */
	onShareAppMessage() {
		const app = this
		const { page } = app
		return {
			title: page.params.share_title,
			path: '/pages/index/index?' + app.$getShareUrlParams()
		}
	},

	/**
	 * 分享到朋友圈
	 * 本接口为 Beta 版本，暂只在 Android 平台支持，详见分享到朋友圈 (Beta)
	 * https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/share-timeline.html
	 */
	onShareTimeline() {
		const app = this
		const { page } = app
		return {
			title: page.params.share_title,
			path: '/pages/index/index?' + app.$getShareUrlParams()
		}
	}
}
</script>

<style lang="scss" scoped>
.container {
	background: #fff;
	padding-bottom: 100rpx;
	min-height: 100vh;
}
</style>
